package com.atguigu.Func;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.common.GmallConfig;
import com.atguigu.util.JdbcUtil_hjy;
import com.atguigu.util.JedisUtil;
import redis.clients.jedis.Jedis;

import java.sql.Connection;
import java.util.List;

/**
 * @author hjy
 * @create 2023/3/27 10:05
 */
public class DimInfoFunction {
    public static JSONObject getDimInfo(Connection connection,String tableName,String filterId,String id) throws Exception {
//        //旁路缓存
//        Jedis jedis = JedisUtil.getJedis();
//        String redisKey="DIM:"+tableName+":"+id;
//        String dimInfo = jedis.get(redisKey);
//        if (dimInfo!=null){
//            jedis.expire(redisKey,24*3600);
//            jedis.close();
//            return JSONObject.parseObject(dimInfo);
//        }

        //从phoenix拿数据
        String sql="select * from "+ GmallConfig.PHOENIX_DB+"."+tableName+" where "+filterId+" ='"+id+"'";
        List<JSONObject> jdbcUtil = JdbcUtil_hjy.getJdbcUtil(connection, sql, JSONObject.class, false);
        JSONObject jsonObject = jdbcUtil.get(0);
//        jedis.setex(redisKey,24*3600,jsonObject.toString());
//        jedis.close();
        return jsonObject;
    }


}
